package com.xunyin.modules.storeroom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.xunyin.common.service.impl.BaseServiceImpl;
import com.xunyin.common.utils.QueryHelpPlus;
import com.xunyin.dozer.service.IGenerator;
import com.xunyin.modules.shareorder.service.dto.ShareCountDto;
import com.xunyin.modules.store.domain.TStore;
import com.xunyin.modules.storeroom.domain.TStoreRoom;
import com.xunyin.modules.storeroom.param.TStoreRoomQueryParam;
import com.xunyin.modules.storeroom.service.TStoreRoomService;
import com.xunyin.modules.storeroom.service.dto.TStoreRoomQueryCriteria;
import com.xunyin.modules.storeroom.service.mapper.TStoreRoomMapper;
import com.xunyin.modules.storeroom.vo.TStoreRoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 * @date 2022-09-19
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class TStoreRoomServiceImpl extends BaseServiceImpl<TStoreRoomMapper, TStoreRoom> implements TStoreRoomService {

    @Autowired
    private IGenerator generator;

    @Autowired
    private TStoreRoomMapper tStoreRoomMapper;

    /**
     * 根据id获取茶厅（包间）信息
     *
     * @return jsonObject
     */
    @Override
    public TStoreRoomVo getInfoTeaChild(Integer id) {
        return tStoreRoomMapper.getInfoTeaChild(id);
    }

    @Override
    public Map<String, Object> queryAll(TStoreRoomQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<TStoreRoom> page = new PageInfo<>(queryAll(criteria));
        //List<TStoreRoomDto> tStoreRoomDto = new ArrayList<>();
        Map<String, Object> map = new LinkedHashMap<>(2);
        map.put("content", page.getList());
        map.put("totalElements", page.getTotal());
        return map;
    }

    @Override
    public List<TStoreRoom> queryAll(TStoreRoomQueryCriteria criteria) {
        return baseMapper.selectList(QueryHelpPlus.getPredicate(TStore.class, criteria));
    }

    /**
     * 获取房间列表
     *
     * @return List<TStoreRoomVo>
     */
    @Override
    public List<TStoreRoomVo> listRoom(TStoreRoomQueryParam queryParam) {
        LambdaQueryWrapper<TStoreRoom> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TStoreRoom::getStoreId, queryParam.getStoreId());
        List<TStoreRoomVo> list = generator.convert(baseMapper.selectList(wrapper), TStoreRoomVo.class);
        return list;
    }

    @Override
    public List<ShareCountDto> findRoomName() {
        return tStoreRoomMapper.findRoomName();
    }
}
